const app = getApp()
const WXAPI = require("../../../../api/newApi")
Page({

  /**
   * 页面的初始数据
   */
  data: {
      list:[
        {},{},{},
      ],
      orderId: '',
      info:{},
      resultInfo:{},
      param:'',
      show: false,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      statusHeight: app.gettop.height,
      status: app.gettop.status,
      navHeight:app.gettop.navHeight,
      mobbleBottom: app.mobile.mobbleBottom
    })
    if(options.param){
      this.data.param = options.param
      // this.getInfo_t()
    }
    if(options.id){
      this.data.orderId = options.id
      // this.getInfo()
    }
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    
  },
  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  // onShareAppMessage: function () {

  // },
  getReceive(){ //点击领取
    this.dialog = this.selectComponent("#auth_dialog"); 
    var token = wx.getStorageSync('token')
    console.log("555555555555",token)
    if(token == ''){
      this.dialog.showPhone()
    }else{
      // this.getuserInfo()
      console.log('已经有token')
      if(this.data.param!=''){ //从二维码进入
        this.getInfo_t()
      }else if(this.data.orderId!=''){
        this.getInfo()
      }else{
        wx.showToast({
          title: '获取资产失败',
          icon:'none'
        })
        console.log('其他情况')
      }
    }
  },
  getSuccess(){ //授权成功
    console.log('授权成功+++')
    setTimeout(() => {
      this.getReceive()
    },300);
    
  },
  back(){
    wx.reLaunch({
      // url: '/pages/assets/assets',
      url:'/pages/userMarket/userMarket'
    })
  },
  getInfo(){ //shareDetail
    console.log(this.data.orderId)
    wx.showLoading({
      title: '加载中',
    })
    var data = {
      orderId: this.data.orderId,
    }
    WXAPI.shareDetail(data, (res) => {
      const data = res.result
      if (res.code == 200) {
        this.setData({
          info: res.result,
          show: true
        })
        wx.hideLoading()
      }
    })
  },
  getInfo_t(){ //扫二维进入
    console.log(this.data.orderId)
    wx.showLoading({
      title: '加载中',
    })
    var data = {
      qrCodeUrl: this.data.param,
    }
    WXAPI.parGiveOrderQrCodeUrl(data, (res) => {
      const data = res.result
      if (res.code == 200) {
        this.setData({
          info: res.result,
          show: true
        })
        this.data.orderId = res.result.orderId
        wx.hideLoading()
      }
    })
  },
  sumit(){ //确认 receive
    wx.showLoading({
      title: '收款中',
    })
    var data = {
      orderId: this.data.orderId,
    }
    WXAPI.receive(data, (res) => {
      const data = res.result
      if (res.code == 200) {
        wx.hideLoading()
        this.data.resultInfo = JSON.stringify(res.result)
        wx.showToast({
          title: '收款成功',
          icon:'success'
        })
        setTimeout(() => {
          wx.navigateTo({
           url: '/userPageA/pages/scan/receive_success/receive_success?info=' + this.data.resultInfo,
          })
        },800);
        
      }else{
        // wx.hideLoading()
      }
    })
  }
})